package com.gxw.www.myapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.Toast;

import com.gxw.www.myapp.widget.titlepop.ActionItem;
import com.gxw.www.myapp.widget.titlepop.TitlePopup;
import com.gxw.www.myapp.widget.titlepop.TitlePopup.OnItemOnClickListener;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * 
 * @author 晓炜
 * 
 */

@ContentView(R.layout.activity_main)
public class MainActivity extends Activity implements OnItemOnClickListener {

	// 定义标题栏上的按钮
	@ViewInject(R.id.imgBtn_main_title)
	private ImageButton imgBtn_main_title;

	// 定义标题栏弹窗按钮
	private TitlePopup titlePopup;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// 无标题
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		ViewUtils.inject(this);
		initView();
		initData();
	}

	@OnClick({ R.id.imgBtn_main_title, R.id.btn_to_left_menu,
			R.id.btn_to_right_menu })
	private void onClick(View v) {

		switch (v.getId()) {
		case R.id.imgBtn_main_title:
			titlePopup.show(v);
			break;

		case R.id.btn_to_left_menu:

			startActivity(new Intent(MainActivity.this, FragActivity.class));

			break;

		case R.id.btn_to_right_menu:

			// startActivity(new Intent(MainActivity.this, FragActivity.class));

			break;

		default:
			break;
		}

	}

	/**
	 * 初始化组件
	 */
	private void initView() {

		// 实例化标题栏弹窗
		titlePopup = new TitlePopup(this, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT);
		titlePopup.setItemOnClickListener(MainActivity.this);
	}

	/**
	 * 初始化数据
	 */
	private void initData() {
		// 给标题栏弹窗添加子类

		titlePopup.addAction(new ActionItem(this, "发起聊天",
				R.drawable.mm_title_btn_compose_normal));
		titlePopup.addAction(new ActionItem(this, "听筒模式",
				R.drawable.mm_title_btn_receiver_normal));
		titlePopup.addAction(new ActionItem(this, "登录网页",
				R.drawable.mm_title_btn_keyboard_normal));
		titlePopup.addAction(new ActionItem(this, "扫一扫",
				R.drawable.mm_title_btn_qrcode_normal));
	}

	@Override
	public void onItemClick(ActionItem item, int position) {
		// TODO Auto-generated method stub

		switch (position) {
		case 0:

			Toast.makeText(MainActivity.this, "发起聊天", 1).show();

			startActivity(new Intent(MainActivity.this, FragActivity.class));

			break;

		case 1:

			Toast.makeText(MainActivity.this, "听筒模式", 1).show();

			break;

		case 2:

			Toast.makeText(MainActivity.this, "登录网页", 1).show();

			break;

		case 3:

			Toast.makeText(MainActivity.this, "扫一扫", 1).show();

			break;

		default:
			break;
		}

	}

}
